<template>
  <div class="ybl">
    <el-table
      height="100"
      :data="tabData2"
      border
      stripe
      size="mini"
      highlight-current-row
      class="tableFlex"
    >
      <el-table-column type="index" label="行号" width="60" />
      <el-table-column label="物料号" width="180">
        <template slot-scope="scope">
          <sItemUid v-model="scope.row.uid" @change="change('uid',scope.$index,$event)" />
        </template>
      </el-table-column>
      <el-table-column prop="name" label="物料名称" />
      <el-table-column prop="model" label="物料型号" />
      <el-table-column prop="process" label="所属工序" width="140">
        <template slot-scope="scope">
          <sProcess v-model="scope.row.process" @change="change('process',scope.$index,$event)" />
        </template>
      </el-table-column>
      <el-table-column label="预计需求" width="100">
        <template slot-scope="scope">
          <el-input
            size="mini"
            :value="scope.row.sum"
            @input="change('sum',scope.$index,$event)"
            @focus="$event.currentTarget.select();"
          />
        </template>
      </el-table-column>
      <el-table-column label="操作" width="77">
        <template slot-scope="scope">
          <el-button @click="change(0,scope.$index);" v-text="'移除'" size="mini" type="danger" />
        </template>
      </el-table-column>
    </el-table>
    <fy :value="tabData" @change="tabData2=$event" />
  </div>
</template>
<script>
import sItemUid from "../../select/sItemUid";
import sProcess from "../../select/sProcess";
import fy from "../../fy";
import tst from "../../tst";
export default {
  components: { sItemUid, sProcess, fy, tst },
  props: {
    value: { default: false }
  },
  watch: {
    value() {
      this.first();
    },
    tabData2: {
      handler(a) {
        // console.log(this.$cp(a), this.$cp(this.$gd));
        this.yh = -1;
      },
      deep: true
    }
  },
  data() {
    return {
      show: true,
      tabData: [],
      tabData2: [],
      title: "",
      yh: -1
    };
  },
  // computed() {return{}},
  created() {
    // console.log(this.tabData);
    this.first();
  },
  methods: {
    rowClick(a, b, c) {
      console.log(a, b, c);
    },
    first() {
      if (this.value && this.value.length >= 0) {
        this.tabData = this.$cp(this.value);
      } else {
        this.tabData = [];
      }
    },
    change(a, b, c) {
      let t = this.$cp(this.tabData2[b]);
      b = this.tabData.getItem(t, true, true);
      switch (a) {
        case "uid":
          this.tabData[b].item = c.id;
          this.tabData[b].uid = c.uid;
          this.tabData[b].name = c.name;
          this.tabData[b].model = c.model;
          break;
        case "process":
          this.tabData[b].process = c;
          break;
        case "sum":
          this.proving(b, c);
          break;
        case 0:
          // this.tabData.splice(b, 1);
          console.log(this.$cp(this.tabData[b]), b);
          break;

        default:
          console.log(a, b, c);
          break;
      }
      this.$emit("change", this.tabData);
    },
    proving(a, b) {
      this.tabData[a].sum = b;
      if (!b || !Number(b)) return;
      let t = b;
      this.tabData[a].sum = t ;
    }
  }
};
</script>

<style lang="less" scoped>
</style>
